package com.meilai.project.controller.mini;


import com.meilai.project.controller.mini.dto.CustomerApplyFollowDTO;
import com.meilai.project.dto.base.ApiResult;
import com.meilai.project.service.business.customer.CustomerApplyFollowRecordService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModelProperty;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;

@RestController
@RequestMapping("/api/mini/customerApplyFollowRecord")
@Api(tags = "小程序-跟进（申请、通过、驳回）")
public class MiniCustomerApplyFollowRecordController {

    @Autowired
    private CustomerApplyFollowRecordService service;

    @ApiModelProperty("申请跟进")
    @PostMapping("/apply")
    public ApiResult<Boolean> applyFollow(@RequestBody @Valid CustomerApplyFollowDTO dto) {
        try {
            return ApiResult.ok(service.applyFollow(dto.getId()));
        } catch (Exception e) {
            e.printStackTrace();
            return ApiResult.err("申请跟进失败");
        }
    }

    @ApiModelProperty("通过申请跟进")
    @PostMapping("/pass")
    public ApiResult<Boolean> pass(@RequestBody @Valid CustomerApplyFollowDTO dto) {
        try {
            return ApiResult.ok(service.pass(dto.getId()));
        } catch (Exception e) {
            e.printStackTrace();
            return ApiResult.err("审核失败");
        }
    }

    @ApiModelProperty("驳回申请跟进")
    @PostMapping("/reject")
    public ApiResult<Boolean> reject(@RequestBody @Valid CustomerApplyFollowDTO dto) {
        try {
            return ApiResult.ok(service.reject(dto.getId()));
        } catch (Exception e) {
            e.printStackTrace();
            return ApiResult.err("审核失败");
        }
    }
}
